package com.hedd.shop.controller;

import com.hedd.shop.pojo.entity.Product;
import com.hedd.shop.pojo.qo.AccurateSearchQO;
import com.hedd.shop.pojo.qo.ProductInsertQO;
import com.hedd.shop.pojo.qo.ProductPagingQO;
import com.hedd.shop.pojo.vo.RespResult;
import com.hedd.shop.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ludi
 * @date:2020/8/29 15:31
 * @description:商品业务控制层
 */
@Controller
@RestController
@RequestMapping("/product")
@Api(tags = "商品业务接口")
public class ProductController extends BaseController {
    @Autowired
    private ProductService productService;

    @GetMapping("/showProductByTypeName")
    @ApiOperation("根据种类展示商品")
    public RespResult showProductByTypeName(String TypeName){
        List<Product> list = productService.selectProductByTypeName(TypeName);
        return returnRespWithSuccess(list);
    }

    @GetMapping("/showProductById")
    @ApiOperation("根据商品id展示商品")
    public RespResult showProductById(Integer productId){
        Product product = productService.selectProductById(productId);
        return returnRespWithSuccess(product);
    }

    @GetMapping("/selectProductOnSearch")
    @ApiOperation("根据关键字（名字）查询商品")
    public RespResult selectProductOnSearch(String keyWords){
        List<Product> list = productService.selectProductOnSearch(keyWords);
        return returnRespWithSuccess(list);
    }

    @PostMapping("/selectProductOnAccurateSearch")
    @ApiOperation("多条件精确查询商品")
    public RespResult selectProductOnAccurateSearch(@RequestBody AccurateSearchQO accurateSearchQO){
        List<Product> list = productService.selectProductOnAccurateSearch(accurateSearchQO);
        return returnRespWithSuccess(list);
    }

    @PostMapping("/selectProductUsingPaging")
    @ApiOperation("分页查询商品")
    public RespResult selectProductUsingPaging(@RequestBody ProductPagingQO productPagingQO){
        List<Product> list = productService.selectProductUsingPaging(productPagingQO);
        return returnRespWithSuccess(list);
    }

    @GetMapping("/selectProductCountByTypeName")
    @ApiOperation("根据商品种类查询商品数量")
    public RespResult selectProductCountByTypeName(String typeName){
        Integer count = productService.selectProductCountByTypeName(typeName);
        return returnRespWithSuccess(count);
    }

    @PostMapping("/insertProductCollection")
    @ApiOperation("添加进收藏夹")
    public RespResult insertProductCollection(@RequestBody ProductInsertQO productInsertQO){
        Integer value = productService.insertProductCollection(productInsertQO);
        return returnRespWithSuccess(value);
    }

}
